package shopping

import (
	"fmt"
)

// 购物车
func Cart() {
	car := make(map[string]float64)
	for {
		var opt int
		fmt.Printf("按1加购，按2结算,按3退出购物车>>")
		fmt.Scan(&opt)
		if opt == 1 {
			var code string
			var weight float64
			fmt.Printf("请输入您要加购的商品编号(F001、F002、F003、F004)>>")
			fmt.Scan(&code)
			fmt.Printf("请问您要购买几斤?(输入数字即可)>>")
			fmt.Scan(&weight)
			Total := weight * fruit_info[code].Price
			car[code] += Total
			fmt.Printf("您加购的%s商品共计:%.2f元\n", fruit_info[code].Name, Total)
			fmt.Println("您的购物车中有如下产品:")
			for code, total := range car {
				fmt.Printf("%s: %.2f元\n", code, total)
			}
		} else if opt == 2 {
			var pay_total float64
			fmt.Println("现在为您结算购物车商品")
			for _, total := range car {
				pay_total += total
			}
			fmt.Printf("您本次结算的总金额为: %.2f元\n", pay_total)

			//要把账户余额修改落盘！
			fmt.Println("我写不出来了.感觉要长脑子了..余额修改落盘未实现...")
			car = make(map[string]float64)
		} else if opt == 3 {
			break
		}
	}
}
